﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using HYRevitCode.FormUtility;
using QuickModel.DuctFastModel;

namespace QuickModel.Forms
{
	public partial class DuctFastModelForm : System.Windows.Forms.Form
	{
		public bool EnableOkButton { get; set; }

		public CloseDuctDlgType DlgCloseType
		{
			get
			{
				return this.m_DlgCloseType;
			}
		}

		public DuctFastModelForm()
		{
			this.InitializeComponent();
			this.m_DlgCloseType = CloseDuctDlgType.Other;
		}

		private void btnSelestLine_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = CloseDuctDlgType.SelectDuctLine;
			base.DialogResult = DialogResult.OK;
		}

		private void btnSelsetSet_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = CloseDuctDlgType.SetButton;
			base.DialogResult = DialogResult.OK;
		}

		private void radFlange_CheckedChanged(object sender, EventArgs e)
		{
			bool @checked = this.radFlange.Checked;
			if (@checked)
			{
				this.btnSelectFlange.Enabled = true;
				this.radFit.Checked = false;
				this.btnSelectFit.Enabled = false;
				DuctFormData.m_bFange = true;
				DuctFormData.m_bFit = false;
				this.pbxFit.BackgroundImage = Resources.QuickModelGray;
				this.pbxFit.BackgroundImageLayout = ImageLayout.Stretch;
				this.btnSelectOK.Enabled = false;
				this.EnableOkButton = false;
			}
		}

		private void radFit_CheckedChanged(object sender, EventArgs e)
		{
			bool @checked = this.radFit.Checked;
			if (@checked)
			{
				this.btnSelectFit.Enabled = true;
				this.radFlange.Checked = false;
				this.btnSelectFlange.Enabled = false;
				DuctFormData.m_bFit = true;
				DuctFormData.m_bFange = false;
				this.pbxFlange.BackgroundImage = Resources.QuickModelGray;
				this.pbxFlange.BackgroundImageLayout = ImageLayout.Stretch;
				this.btnSelectOK.Enabled = false;
				this.EnableOkButton = false;
			}
		}

		private void btnSelectFlange_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = CloseDuctDlgType.SelectFlange;
			base.DialogResult = DialogResult.OK;
		}

		private void btnSelectFit_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = CloseDuctDlgType.SelectFit;
			base.DialogResult = DialogResult.OK;
		}

		private void radAppoint_CheckedChanged(object sender, EventArgs e)
		{
			bool @checked = this.radAppoint.Checked;
			if (@checked)
			{
				this.cmbDuctHeight.Enabled = true;
				this.radAuto.Checked = false;
				this.btnSelectSize.Enabled = false;
				this.pbxSize.BackgroundImage = Resources.QuickModelGray;
				this.pbxSize.BackgroundImageLayout = ImageLayout.Stretch;
				bool flag = this.cmbDuctHeight.Text.IsEmpty<char>();
				if (flag)
				{
					this.btnSelectOK.Enabled = false;
				}
				else
				{
					bool flag2 = this.EnableOkButton && !this.cmbDuctHeight.Text.IsEmpty<char>();
					if (flag2)
					{
						this.btnSelectOK.Enabled = true;
					}
					else
					{
						bool flag3 = this.pbxDuctLine.BackgroundImage.Tag == Resources.QuickModelGreen.Tag && (this.pbxFlange.BackgroundImage.Tag == Resources.QuickModelGreen.Tag || this.pbxFit.BackgroundImage.Tag == Resources.QuickModelGreen.Tag);
						if (flag3)
						{
							this.btnSelectOK.Enabled = true;
						}
					}
				}
			}
		}

		private void radAuto_CheckedChanged(object sender, EventArgs e)
		{
			bool @checked = this.radAuto.Checked;
			if (@checked)
			{
				this.btnSelectSize.Enabled = true;
				this.radAppoint.Checked = false;
				this.btnSelectSize.Enabled = true;
				this.cmbDuctHeight.Enabled = false;
				this.btnSelectOK.Enabled = false;
				this.EnableOkButton = false;
			}
		}

		private void btnSelectOK_Click(object sender, EventArgs e)
		{
			bool @checked = this.radAppoint.Checked;
			if (@checked)
			{
				bool flag = JudgeGroup.IsNumber(this.cmbDuctHeight.Text.Trim());
				if (flag)
				{
					DuctFormData.m_dDuctHeight = this.cmbDuctHeight.Text.ToDouble(0.0);
				}
				else
				{
					YJKMessageBox.Show("风管高度为正整数!");
				}
			}
			DuctFormData.m_bAppoint = this.radAppoint.Checked;
			DuctFormData.m_bAuto = this.radAuto.Checked;
			this.m_DlgCloseType = CloseDuctDlgType.NextButton;
			base.DialogResult = DialogResult.OK;
		}

		private void btnSelectCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void DuctFastModelForm_Load(object sender, EventArgs e)
		{
			base.Icon = Resource.YArchitechIcon;
			AllDuctData.DicBuildDatas = new Dictionary<int, DuctBuildData>();
			this.btnSelectOK.Enabled = false;
			this.AddControlGroup();
			this.m_ControlInfoManager = new ControlInfoManager(this, this.m_lstControlGroup, null, null);
			this.m_ControlInfoManager.SetControlInfoToForm();
			bool flag = !this.radFlange.Checked && !this.radFit.Checked;
			if (flag)
			{
				this.radFlange.Checked = true;
			}
			bool flag2 = this.cmbDuctHeight.ItemsCount == 0;
			if (flag2)
			{
				bool flag3 = this.cmbDuctHeight.SelectedItem == null;
				if (flag3)
				{
					this.cmbDuctHeight.Text = "320";
				}
				foreach (string item in DataEnum.DuctHeight())
				{
					this.cmbDuctHeight.AddItem(item);
				}
			}
			bool flag4 = !this.radAppoint.Checked && !this.radAuto.Checked;
			if (flag4)
			{
				this.radAppoint.Checked = true;
			}
			this.btnSelectOK.Enabled = this.EnableOkButton;
		}

		private void btnSelectSize_Click(object sender, EventArgs e)
		{
			this.m_DlgCloseType = CloseDuctDlgType.SelectSizeText;
			base.DialogResult = DialogResult.OK;
		}

		private void AddControlGroup()
		{
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.btnSelestLine, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.pbxDuctLine, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.btnSelectFlange, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.pbxFlange, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.btnSelectFit, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.pbxFit, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.radFlange, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.radFit, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.radAppoint, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.radAuto, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.btnSelectSize, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.pbxSize, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.cmbDuctHeight, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.btnSelectOK, false));
			this.m_lstControlGroup.Add(new KeyValuePair<System.Windows.Forms.Control, bool>(this.btnSelectCancel, false));
		}

		private void DuctFastModelForm_FormClosed(object sender, FormClosedEventArgs e)
		{
			bool flag = this.m_ControlInfoManager != null;
			if (flag)
			{
				this.m_ControlInfoManager.GetControlInfoToXml();
			}
		}

		private void DuctFastModelForm_KeyDown(object sender, KeyEventArgs e)
		{
			bool flag = e.KeyValue == 27;
			if (flag)
			{
				base.DialogResult = DialogResult.Cancel;
			}
		}

		private void DuctFastModelForm_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
		{
			bool flag = e.KeyValue == 27;
			if (flag)
			{
				base.DialogResult = DialogResult.Cancel;
			}
		}

		private ControlInfoManager m_ControlInfoManager = null;

		private CloseDuctDlgType m_DlgCloseType;

		private List<KeyValuePair<System.Windows.Forms.Control, bool>> m_lstControlGroup = new List<KeyValuePair<System.Windows.Forms.Control, bool>>();
	}
}
